// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed class MlEstimateModelMemoryRequestParameters : RequestParameters<MlEstimateModelMemoryRequestParameters>
	{
	}

	public sealed partial class MlEstimateModelMemoryRequest : PlainRequestBase<MlEstimateModelMemoryRequestParameters>
	{
		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningEstimateModelMemory;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonInclude]
		[JsonPropertyName("analysis_config")]
		public Elastic.Clients.Elasticsearch.Ml.AnalysisConfig? AnalysisConfig { get; set; }

		[JsonInclude]
		[JsonPropertyName("max_bucket_cardinality")]
		public Dictionary<Elastic.Clients.Elasticsearch.Field, long>? MaxBucketCardinality { get; set; }

		[JsonInclude]
		[JsonPropertyName("overall_cardinality")]
		public Dictionary<Elastic.Clients.Elasticsearch.Field, long>? OverallCardinality { get; set; }
	}

	public sealed partial class MlEstimateModelMemoryRequestDescriptor<TDocument> : RequestDescriptorBase<MlEstimateModelMemoryRequestDescriptor<TDocument>, MlEstimateModelMemoryRequestParameters>
	{
		internal MlEstimateModelMemoryRequestDescriptor(Action<MlEstimateModelMemoryRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public MlEstimateModelMemoryRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningEstimateModelMemory;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		private Elastic.Clients.Elasticsearch.Ml.AnalysisConfig? AnalysisConfigValue { get; set; }

		private AnalysisConfigDescriptor<TDocument> AnalysisConfigDescriptor { get; set; }

		private Action<AnalysisConfigDescriptor<TDocument>> AnalysisConfigDescriptorAction { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, long>? MaxBucketCardinalityValue { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, long>? OverallCardinalityValue { get; set; }

		public MlEstimateModelMemoryRequestDescriptor<TDocument> AnalysisConfig(Elastic.Clients.Elasticsearch.Ml.AnalysisConfig? analysisConfig)
		{
			AnalysisConfigDescriptor = null;
			AnalysisConfigDescriptorAction = null;
			AnalysisConfigValue = analysisConfig;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor<TDocument> AnalysisConfig(AnalysisConfigDescriptor<TDocument> descriptor)
		{
			AnalysisConfigValue = null;
			AnalysisConfigDescriptorAction = null;
			AnalysisConfigDescriptor = descriptor;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor<TDocument> AnalysisConfig(Action<AnalysisConfigDescriptor<TDocument>> configure)
		{
			AnalysisConfigValue = null;
			AnalysisConfigDescriptor = null;
			AnalysisConfigDescriptorAction = configure;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor<TDocument> MaxBucketCardinality(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>> selector)
		{
			MaxBucketCardinalityValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>());
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor<TDocument> OverallCardinality(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>> selector)
		{
			OverallCardinalityValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (AnalysisConfigDescriptor is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, AnalysisConfigDescriptor, options);
			}
			else if (AnalysisConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, new AnalysisConfigDescriptor<TDocument>(AnalysisConfigDescriptorAction), options);
			}
			else if (AnalysisConfigValue is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, AnalysisConfigValue, options);
			}

			if (MaxBucketCardinalityValue is not null)
			{
				writer.WritePropertyName("max_bucket_cardinality");
				JsonSerializer.Serialize(writer, MaxBucketCardinalityValue, options);
			}

			if (OverallCardinalityValue is not null)
			{
				writer.WritePropertyName("overall_cardinality");
				JsonSerializer.Serialize(writer, OverallCardinalityValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class MlEstimateModelMemoryRequestDescriptor : RequestDescriptorBase<MlEstimateModelMemoryRequestDescriptor, MlEstimateModelMemoryRequestParameters>
	{
		internal MlEstimateModelMemoryRequestDescriptor(Action<MlEstimateModelMemoryRequestDescriptor> configure) => configure.Invoke(this);
		public MlEstimateModelMemoryRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningEstimateModelMemory;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		private Elastic.Clients.Elasticsearch.Ml.AnalysisConfig? AnalysisConfigValue { get; set; }

		private AnalysisConfigDescriptor AnalysisConfigDescriptor { get; set; }

		private Action<AnalysisConfigDescriptor> AnalysisConfigDescriptorAction { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, long>? MaxBucketCardinalityValue { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, long>? OverallCardinalityValue { get; set; }

		public MlEstimateModelMemoryRequestDescriptor AnalysisConfig(Elastic.Clients.Elasticsearch.Ml.AnalysisConfig? analysisConfig)
		{
			AnalysisConfigDescriptor = null;
			AnalysisConfigDescriptorAction = null;
			AnalysisConfigValue = analysisConfig;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor AnalysisConfig(AnalysisConfigDescriptor descriptor)
		{
			AnalysisConfigValue = null;
			AnalysisConfigDescriptorAction = null;
			AnalysisConfigDescriptor = descriptor;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor AnalysisConfig(Action<AnalysisConfigDescriptor> configure)
		{
			AnalysisConfigValue = null;
			AnalysisConfigDescriptor = null;
			AnalysisConfigDescriptorAction = configure;
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor MaxBucketCardinality(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>> selector)
		{
			MaxBucketCardinalityValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>());
			return Self;
		}

		public MlEstimateModelMemoryRequestDescriptor OverallCardinality(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>> selector)
		{
			OverallCardinalityValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, long>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (AnalysisConfigDescriptor is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, AnalysisConfigDescriptor, options);
			}
			else if (AnalysisConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, new AnalysisConfigDescriptor(AnalysisConfigDescriptorAction), options);
			}
			else if (AnalysisConfigValue is not null)
			{
				writer.WritePropertyName("analysis_config");
				JsonSerializer.Serialize(writer, AnalysisConfigValue, options);
			}

			if (MaxBucketCardinalityValue is not null)
			{
				writer.WritePropertyName("max_bucket_cardinality");
				JsonSerializer.Serialize(writer, MaxBucketCardinalityValue, options);
			}

			if (OverallCardinalityValue is not null)
			{
				writer.WritePropertyName("overall_cardinality");
				JsonSerializer.Serialize(writer, OverallCardinalityValue, options);
			}

			writer.WriteEndObject();
		}
	}
}